package com.ydgg.ltar.api;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ydgg.ltar.model.ArBuilding;
import com.ydgg.ltar.model.ArBuildingList;
import com.ydgg.ltar.service.ArBuildingListService;
import com.ydgg.ltar.service.ArBuildingService;


/**
 * ar识楼
 * 作者： 张叶
 * 创建时间：2018年12月12日  下午4:32:13
 */
@Controller
@RequestMapping("api/arBuilding")
public class ArBuildingApi {

	@Autowired
	private ArBuildingService arBuildingService;
	@Autowired
	private ArBuildingListService arBuildingListService;
	

	/**
	 * 列表
	 * 作者： 张叶
	 * 创建时间：2018年12月12日  下午4:34:12
	 */
	@ResponseBody
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public ApiResult list(String lat,String lng) {
		ApiResult result = new ApiResult();
		if(lat != null && !"".equals(lat) &&
				lng != null && !"".equals(lng)){
			List<ArBuilding> list = arBuildingService.selectByDistance(lat,lng);
			if(list.size() > 0){
				String latlngList = "";
				List<ArBuildingList> ablList = new ArrayList<ArBuildingList>();
				for(ArBuilding ab :list){
					ablList = arBuildingListService.selectByWhere(" and status = 'on' and ar_building_id = " + ab.getId());
					if(ablList.size() > 0){
						for(ArBuildingList abl :ablList){
							latlngList += abl.getLat() + "," + abl.getLng() + ";";
						}
						latlngList = latlngList.substring(0,latlngList.length() -1);
						ab.setLatlngList(latlngList);
						latlngList = "";
					}
				}
				result.data.put("arBuildingList", list);
				result.data.put("distance", 50);
				result.msg.status = 0;
				result.msg.desc = "获取成功";
			}else{
				result.msg.status = 1;
				result.msg.desc = "暂无数据";
			}
		}else{
			result.msg.status = 3;
			result.msg.desc = "参数不能为空";
		}
		return result;
	}
	
	
	/**
	 * 案例
	 * 作者： 张叶
	 * 创建时间：2018年12月29日  上午9:49:35
	 */
	@ResponseBody
	@RequestMapping(value = "/example")
	public ApiResult example(){
		ApiResult result = new ApiResult();
		List<Map<String,Object>> list = arBuildingService.selectExample();
		if(list.size() > 0){
			result.data.put("abList", list);
			result.msg.status = 0;
			result.msg.desc = "获取成功";
		}else{
			result.msg.status = 1;
			result.msg.desc = "暂无数据";
		}
		return result;
	}
}
